package service

import (
	"ams/dao"
	"lib/structs/ams"
	"lib/structs/tables"
)

var ClientService = new(clientService)

type clientService struct {
}

func (s clientService) Page(in ams.SearchClientPage) (rli []ams.ClientDto, total int64, err error) {
	var li []tables.AmsClient
	li, total, err = dao.ClientDao.FindPage(in)
	rli = make([]ams.ClientDto, len(li))
	for i, v := range li {
		item := ams.ClientDto{
			AmsClient: v,
		}
		if val, ok := dao.OnlineMap.Load(v.UniqueCode); ok {
			item.LastMsgTime = val.(int64)
			item.IsOnline = true
		}
		rli[i] = item
	}
	return
}
